package view.render
{
	import flash.text.TextFormat;
	
	import enums.main.UISize;
	
	import feathers.controls.Button;
	import feathers.controls.renderers.DefaultListItemRenderer;
	import feathers.data.ListCollection;
	
	import model.vo.ItemVo;
	
	import starling.display.Image;
	import starling.utils.Color;
	
	import util.AtlasTextureGenerator;
	
	/**
	 * 带有素材列表的滚动条item基类
	 * @author £iang
	 * 
	 */	
	public class BaseItemScrollerItem extends BaseScrollerItem
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 通用item皮肤 
		 * @return 
		 * 
		 */		
		protected function commonItem():DefaultListItemRenderer
		{
			var renderer:DefaultListItemRenderer = new DefaultListItemRenderer();
			renderer.width = UISize.MAIN_W * 0.6;
			renderer.height = UISize.ITEM_LIST_ITEM_H * UISize.DPI_SCALE;
			renderer.defaultLabelProperties.textFormat = new TextFormat( "微软雅黑,宋体", 24 * UISize.DPI_SCALE, 
				Color.WHITE, false );
			renderer.horizontalAlign = Button.HORIZONTAL_ALIGN_LEFT;
			renderer.verticalAlign = Button.VERTICAL_ALIGN_MIDDLE;
			renderer.itemHasAccessory = false;
			renderer.gap = 0;
			renderer.defaultLabelProperties.wordWrap = true;
			return renderer;
		}
		
		/**
		 * 将itemVo转换为列表用object 
		 * @param itemVo itemVo
		 * @return object 
		 * 
		 */		
		public static function mapItemVo2ListObj( itemVo:ItemVo, num:int = 0 ):Object
		{
			var tmpObj:Object = new Object();
			var tmpImage:Image;
			var labelStr:String = itemVo.jp;
			
			if ( num > 0 )
				labelStr = itemVo.jp + "×" + num + "　";
			tmpObj.label = labelStr;
			tmpImage = new Image(  AtlasTextureGenerator.getItemTextureById( 
				itemVo.iconId
			) );
			tmpImage.scaleX = tmpImage.scaleY = UISize.DPI_SCALE;
			tmpObj.icon = tmpImage;
			tmpObj.itemId = itemVo.itemId;
			return tmpObj;
		}
		
		/**
		 * 析构itemList中的数据 
		 * @param listData listCollection数据
		 * 
		 */		
		protected function disposeItemListData( listData:ListCollection ):void
		{	
			if ( listData )
			{
				var len:int = listData.length;
				for ( var i:int = 0; i < len; i ++ )
				{
					( listData.data[ i ].icon as Image ).dispose();
					( listData.data[ i ].icon as Image ).texture.dispose();
					listData.data[ i ].icon = null; 
					listData.data[ i ] = null;
				}
			}
			
			listData.removeAll();
			listData = null;
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function BaseItemScrollerItem()
		{
			super();
		}
	}
}